/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VisualizadorAnotacaoDialog.java
 *
 * Created on 13/11/2011, 16:04:45
 */
package lp2.projeto.anotacao;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import lp2.projeto.agenda.Imagem;
import lp2.projeto.agenda.Som;
import lp2.projeto.agenda.Texto;

/**
 *
 * @author Tercio de Melo
 */
public class VisualizadorAnotacaoDialog extends javax.swing.JDialog {

	private static final long serialVersionUID = -6340018772588639885L;
	/** Creates new form VisualizadorAnotacaoDialog */
	
	private Anotacao anotacao;
	private List<String> nomeDasImagens, nomeDosSons, nomeDosTextos;
	
    public VisualizadorAnotacaoDialog(java.awt.Frame parent, boolean modal, Anotacao anotacao) {
        super(parent, modal);
        this.anotacao = anotacao;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        textoArea = new javax.swing.JTextArea();
        fecharButton = new javax.swing.JButton();
        textoLabel = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaImagensList = new javax.swing.JList();
        listaImagensLabel = new javax.swing.JLabel();
        verSomButton = new javax.swing.JButton();
        removerSomButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        listaSonsList = new javax.swing.JList();
        listaSonsLabel = new javax.swing.JLabel();
        verImagemButton = new javax.swing.JButton();
        removerImagemButton = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        listaTextoList = new javax.swing.JList();
        verTextoButton = new javax.swing.JButton();
        removerTextoButton = new javax.swing.JButton();
        listaTextosLabel = new javax.swing.JLabel();
        novaImagemButton = new javax.swing.JButton();
        novoSomButton = new javax.swing.JButton();
        novoTextoButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        textoArea.setColumns(20);
        textoArea.setRows(5);
        jScrollPane1.setViewportView(textoArea);

        fecharButton.setText("Fechar");

        textoLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        textoLabel.setText("Texto");
        
        nomeDasImagens = new ArrayList<String>();
        for(Imagem img : anotacao.getImagens())
        	nomeDasImagens.add(img.getNome());
        
        listaImagensList.setModel(new javax.swing.AbstractListModel() {
        	String[] strings = (String[]) nomeDasImagens.toArray(new String[0]);
            public int getSize() { 	return strings.length; }
            public Object getElementAt(int i) { return anotacao.getImagens().get(i); }
        });
        jScrollPane2.setViewportView(listaImagensList);

        listaImagensLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        listaImagensLabel.setText("Imagens");

        verSomButton.setText("Ver");

        removerSomButton.setText("Remover");
        removerSomButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int index = listaSonsList.getSelectedIndex();
				listaSonsList.remove(index);
				anotacao.getSons().remove(index);
			}
		});

        nomeDosSons = new ArrayList<String>();
        for(Som som : anotacao.getSons())
        	nomeDosSons.add(som.getNome());
        
        listaSonsList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = (String[]) nomeDosSons.toArray(new String[0]);
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return anotacao.getSons().get(i); }
        });
        jScrollPane3.setViewportView(listaSonsList);

        listaSonsLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        listaSonsLabel.setText("Sons");

        verImagemButton.setText("Ver");

        removerImagemButton.setText("Remover");
        removerImagemButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int index = listaImagensList.getSelectedIndex();
				anotacao.getSons().remove(index);
				listaImagensList.remove(index);
			}
		});

        nomeDosTextos = new ArrayList<String>();
        for(Texto txt : anotacao.getTextos())
        	nomeDosTextos.add(txt.getNome());
        
        listaTextoList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = (String[]) nomeDosTextos.toArray(new String[0]);
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return anotacao.getTextos().get(i); }
        });
        jScrollPane4.setViewportView(listaTextoList);

        verTextoButton.setText("Ver");
        verTextoButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				textoArea.setText(((Texto) listaTextoList.getSelectedValue()).getConteudo());
			}
		});

        removerTextoButton.setText("Remover");
        removerTextoButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int index = listaTextoList.getSelectedIndex();
				listaTextoList.remove(index);
				anotacao.getTextos().remove(index);
			}
		});

        listaTextosLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        listaTextosLabel.setText("Textos");

        novaImagemButton.setText("Nova Imagem");
        novaImagemButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
			}
		});

        novoSomButton.setText("Novo Som");
        novoSomButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
			}
		});

        novoTextoButton.setText("Novo Texto");
        novoTextoButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
			}
		});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                                    .addComponent(listaImagensLabel)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                                    .addComponent(listaSonsLabel))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(41, 41, 41)
                                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(listaTextosLabel)
                                            .addGap(52, 52, 52)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(novoSomButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(novaImagemButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(novoTextoButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                                        .addGap(16, 16, 16))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(verImagemButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(removerImagemButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                                .addComponent(verTextoButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(removerTextoButton)))
                        .addGap(47, 47, 47)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(fecharButton, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(98, 98, 98)
                                .addComponent(textoLabel)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(verSomButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removerSomButton)
                        .addGap(462, 462, 462))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(listaImagensLabel)
                    .addComponent(textoLabel)
                    .addComponent(listaTextosLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(verImagemButton)
                                    .addComponent(removerImagemButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(listaSonsLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(verTextoButton)
                                    .addComponent(removerTextoButton))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(novaImagemButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(novoSomButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(novoTextoButton))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fecharButton)
                    .addComponent(verSomButton)
                    .addComponent(removerSomButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                VisualizadorAnotacaoDialog dialog = new VisualizadorAnotacaoDialog(new javax.swing.JFrame(), true, new Anotacao("Anotacao qualque"));
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton fecharButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JLabel listaImagensLabel;
    private javax.swing.JList listaImagensList;
    private javax.swing.JLabel listaSonsLabel;
    private javax.swing.JList listaSonsList;
    private javax.swing.JList listaTextoList;
    private javax.swing.JLabel listaTextosLabel;
    private javax.swing.JButton novaImagemButton;
    private javax.swing.JButton novoSomButton;
    private javax.swing.JButton novoTextoButton;
    private javax.swing.JButton removerImagemButton;
    private javax.swing.JButton removerSomButton;
    private javax.swing.JButton removerTextoButton;
    private javax.swing.JTextArea textoArea;
    private javax.swing.JLabel textoLabel;
    private javax.swing.JButton verImagemButton;
    private javax.swing.JButton verSomButton;
    private javax.swing.JButton verTextoButton;
    // End of variables declaration
}
